import redis
#定义ip和端口
host = 'localhost'
port = 6379

#建立连接
r = redis.Redis(host=host,port=port)



#字符串
# ex过期时间 单位秒S
# r.set('name', 'Jack', ex=20)
# ret = r.get('name')
# print(ret)



#列表
# r.lpush('object', 'one')
# r.lpush('object', 'two')
# r.lpush('object', 'three')
# r.lpush('object', 'four')
# r.lpush('object', 'five')
# r.lpush('object', 'six')
# ret = r.lrange('object', 0, 5)
# print(ret[::-1], len(ret))


#集合
# r.hset('userinfo', 'name', 'Jack')
# r.hset('userinfo', 'age', 20)
# r.hset('userinfo', 'phone', '110110110110')
# r.hset('userinfo', 'email', '123@gmail.com')
# ret = r.hgetall('userinfo')
# print(ret)



#有序集合
# r.zadd("ret1", n1=11, n2=22)
# r.zadd("ret2", 'm1', 22, 'm2', 44)

# print(r.zcard("ret1"))
# print(r.zcard("ret2"))
# print(r.zrange("ret1", 0, -1))
# print(r.zrange("ret2", 0, -1, withscores=True))




#列表操作
# r.lpush('zhoulei',1)
# #设置过期时间
# r.expire('zhoulei',30)

# #打印过期时间
# print(r.ttl('zhoulei'))
# #打印列表长度
# print(r.llen('zhoulei'))




# r.set('a','123')
# print(r.get('a'))
# r.delete('a')

# print(r.lrange('a', 0, -1))
# r.lpush('a',1)
# print(r.llen('a'))